import axios from 'axios'

// axios.defaults.baseURL = 'http://httpbin.org'

const instance = axios.create({
  baseURL: 'http://httpbin.org'
})

function request1() {
  return instance.get('/get', {
    params: {
      name: 'get请求',
      age: 18
    }
  })
}

function request2() {
  return instance.post('/post', {
    data: {
      name: 'post请求',
      age: 18
    }
  })
}

axios.all([request1(), request2()]).then(
  axios.spread((res1, res2) => {
    console.log(res1)
    console.log(res2)
  })
)

axios.interceptors.request.use(
  (config) => {
    console.log(config)
    return config
  },
  (err) => {
    console.log(err)
    return err
  }
)
axios.interceptors.response.use(
  (config) => {
    console.log(config)
    return config
  },
  (err) => {
    console.log(err)
    return err
  }
)

// Promise可以有类型
// new Promise<string>((resolve,reject)=>{
//   resolve("123")
// }).then(res=>{
// })
